package com.lyc.controller.admin;

import com.lyc.pojo.Comment;
import com.lyc.pojo.Result;
import com.lyc.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comments/admin")
public class AdminCommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 获取所有评论（供管理端使用）
     *
     * @return 所有评论列表
     */
    @GetMapping("/all")
    public Result<List<Comment>> getAllComments() {
        List<Comment> comments = commentService.getAllComments();
        return Result.success(comments);
    }

    /**
     * 管理端删除评论
     *
     * @param id 评论ID
     * @return 操作结果
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteComment(@PathVariable Integer id) {
        boolean isSuccess = commentService.deleteCommentByAdmin(id);
        if (isSuccess) {
            return Result.success();
        } else {
            return Result.error("删除评论失败，可能评论不存在");
        }
    }

    /**
     * 管理端批量删除评论
     *
     * @param commentIds 评论ID列表
     * @return 操作结果
     */
    @DeleteMapping("/batch-delete")
    public Result batchDeleteComments(@RequestBody List<Integer> commentIds) {
        boolean isSuccess = commentService.batchDeleteCommentsByAdmin(commentIds);
        if (isSuccess) {
            return Result.success();
        } else {
            return Result.error("批量删除评论失败");
        }
    }
}